package com.hspedu.newData.dmsxl.数组.二分查找;
/**
 * @Author: yh
 * @description: 
 * @CreateTime: 2025-05-07 
 * @Version: 1.0
 */

public class LC162寻找峰值 {

    // todo
    public int findPeakElement(int[] nums) {

        int i = 0;
        int j = nums.length - 1;

        int mid = i + (j-i)/2;
        while(i<j && mid>0 && mid< nums.length - 1){
            mid = i + (j-i)/2;
            if (nums[mid]>nums[mid-1] && nums[mid] > nums[mid+1]){
                return mid;
            } else if (nums[mid]<nums[mid-1] && nums[mid]>nums[mid+1]) {
                j = mid-1;
            } else if (nums[mid]<nums[mid+1] && nums[mid]>nums[mid-1]) {
                i=mid+1;
            }else {
                i = mid;
            }
        }

        return i;
    }
}
